<div class="page  has-sidebar-left height-full">
    <header class="blue accent-3 relative">
        <div class="container-fluid text-white">
            <div class="row p-t-b-10 ">
                <div class="col">
                    <h4>
                        <i class="icon-user"></i> 用户管理 <span class=" badge badge-dark r-20">{$count} 人</span>
                    </h4>
                </div>
            </div>
            <div class="row">
                <ul class="nav responsive-tab nav-material nav-material-white">


                    <li><a class="nav-link active" href="{:url('vip/index')}"><i class="icon icon-drivers-license"></i>用户列表</a>
                    </li>
                    <li><a class="nav-link " href="{:url('user/index')}"><i
                            class="icon icon-drivers-license"></i>代理列表</a></li>

                    <?php if(session('power')=='0'){?>
                    <li><a class="nav-link" href="{:url('vip/add')}"><i class="icon icon-donut_small"></i> 添加</a></li>
                    <?php } ?>

                </ul>
            </div>
        </div>
    </header>


    <div class="container-fluid animatedParent animateOnce">
        <div class="tab-content my-3">
            <div class="tab-pane animated fadeInUpShort show active go">
                <div class="row my-3">
                    <div class="col-md-12">


                        <div class="card ">


                            <div class="card-body">
                                <div class="card-body tab-pane step-content" style="display: block;">
                                    <div class="card-title">用户列表       <?php if(session('power')=='0'){?>  <span
                                            class=" badge badge-Light r-20">有 {$vip_daoqi} 人的会员已到期或即将在10天内到期</span>
                                    </div>
                                    <?php } ?>


                                    <div class="sw-container tab-content">


                                        <form class="validate" method="get" action="{:url('vip/index')}">
                                            <div class="form-row">
                                                <div class="form-group col-md-12 focused"></div>


                                                <div class="form-group  col-md-12  focused">
                                                    <input class="form-control form-control-lg"
                                                           placeholder="&nbsp;账户 / 昵称" type="text" name="key"
                                                           placeholder="输入想检索的用户">
                                                </div>


                                                <div class="form-group col-md-6 focused">
                                                    <div class="card-title">会员到期时间</div>
                                                    <input type="date" name="start" class="form-control-lg">

                                                </div>

                                                <div class="form-group col-md-6 focused">
                                                    <div class="card-title">会员到期时间</div>
                                                    <input type="date" name="end" class="form-control-lg">


                                                </div>
                                                <input type="hidden" name="parentid" value="{$parentid}">


                                                <div class="form-group col-md-12 focused">
                                                    <button type="submit" onclick="dangetian()"
                                                            class="btn btn-primary form-control form-control-lg">检索
                                                    </button>
                                                </div>


                                            </div>

                                        </form>


                                    </div>


                                    <?php if(session('power')=='0'){?>
                                    <hr>
                                    <h6>批量快捷操作</h6>

                                    <p>
                                        <a href="javascript:;" onclick="del('')" class="btn-single"><span
                                                class="badge badge-danger">删除</span></a>
                                        <a href="javascript:;" onclick="status('1','')" class="btn-single"><span
                                                class="badge badge-success">解封</span></a>
                                        <a href="javascript:;" onclick="status('0','')" class="btn-single"><span
                                                class="badge badge-danger">封号</span></a>
                                        <a href="javascript:;" onclick="ctime('')" class="btn-single"><span
                                                class="badge badge-dark">时间补偿</span></a>
                                    </p>

                                    <p><small>Tips: [ 时间补偿 ] 是面向所有会员！也就是说只要是会员用户且会员未到期都会延长会员时间.( 通常用于活动/节日赠送 或 服务器停机维护补偿
                                        )</small></p>
                                    <hr>


                                    <?php } ?>

                                </div>

                            </div>


                            <div class="table-responsive">


                                <table class="table table-hover r-0">
                                    <thead>
                                    <tr class="no-b">
                                        <th>
                                            <!--<input id="checkall" name="checkall" value="全选" type="checkbox" >--></th>
                                        <th>#</th>
                                        <th>昵称</th>
                                        <th>账户</th>
                                        <th>状态</th>

                                        <th>最后登陆时间</th>
                                        <th>会员到期时间</th>
                                        <?php if(session('power')=='0'){?>
                                        <th>上级</th>
                                        <?php } ?>
                                        <th>余额</th>
                                        <th>积分</th>

                                        <?php if(session('power')=='0'){?>
                                        <th></th>
                                        <th></th>
                                        <th></th>

                                        <?php } ?>
                                    </tr>
                                    </thead>


                                    <tbody>


                                    {volist name="list" id="vo"}
                                    <tr>
                                        <td><input name="checkname" value="{$vo.id}" type="checkbox"></td>
                                        <td><small>{$vo.id}</small></td>


                                        <!--


                                              <td>
                                                   <div class="avatar avatar-md mr-3 mt-1 float-left">
                                                       <span class="avatar-letter avatar-letter-z  avatar-md circle"></span>
                                                   </div>
                                                   <div>
                                                       <div>
                                                           <small><span class="badge badge-light">{$vo.id}</span></small>
                                                       </div>
                                                       <small> <span class="badge badge-light">{$vo.nick_name}</span></small>
                                                   </div>
                                               </td>


                                 -->


                                        <td><small><span class="badge badge-light r-3">{$vo.nick_name}</span></small>
                                        </td>

                                        <td><small><span style="color: #03a9f4;">{$vo.username}</span></small></td>

                                        <td><small> <a onclick="status('{$vo.status==\'1\'?\'0\':\'1\'}','{$vo.id}')">


                                            {$vo.status==='1'?' <span class="btn-fab btn-fab-sm shadow btn-success"><i
                                                class="icon icon-check-circle "></i>    </span> ':'<span
                                                class="  btn-fab btn-fab-sm shadow btn-Danger "><i
                                                class="icon icon-minus-circle blink"></i>      </span>'}


                                        </a></small></td>
                                        <!--  <td> <small><span class="badge badge-light">{$vo.ctime|date="Y-m-d H:i:s",###}</span></small></td>  生成时间 -->


                                        <td><small><span
                                                class="badge badge-light"> <?php  if($vo['logintime']=='0')    {     echo '未登陆';   }else{     echo date('Y-m-d H:i:s',$vo['logintime']);   }   ?></span>
                                        </small></td>
                                        <td>
                                            <small>
                                                <a onclick="btime('{$vo.id}')">
                                                    <?php
                                                     if($vo['type']=='1') {
                                                      echo '<span class=" btn btn-Secondary btn-xs  "><i
                                                        class="icon-beenhere "></i> 永久会员 </span>';
                                                    }else{
                                                    if($vo['lasttime']=='0')
                                                    {
                                                    echo '<span class=" btn btn-Danger btn-xs  ">未充值</span>';
                                                    }elseif($vo['lasttime']< time()){
                                                    echo ' <span class=" btn btn-Warning btn-xs ">已于'.date('Y-m-d',$vo['lasttime']).'过期</span>
                                                    <!--  <span style="color:red">'.date('Y-m-d H:i:s',$vo['lasttime']).'</span>-->
                                                    ';
                                                    }else{
                                                    echo '<span class=" btn btn-Primary btn-xs  ">'.date('Y-m-d H:i:s',$vo['lasttime']).'</span>';
                                                    }
                                                    }

                                                    ?>
                                                </a>
                                            </small>
                                        </td>

                                        <?php if(session('power')=='0'){?>
                                        <td>
                                            <small><?php echo $vo['parentid']=='0'?'暂无归属':gui($vo['parentid']) ?></small>
                                        </td>
                                        <?php  } ?>

                                        <td><small><span class="badge badge-light r-3">¥ {$vo.money}</span></small></td>
                                        <td><small>{$vo.sign}</small></td>


                                        <?php if(session('power')=='0'){?>
                                        <td>
                                            <a href="{:url('vip/update',['id'=>$vo['id']])}" title="编辑"> <span
                                                    class="  btn-fab btn-fab-sm shadow btn-Primary"><i
                                                    class="icon icon-pencil"></i>      </span> </a>
                                        </td>
                                        <td>
                                            <a onclick="del('{$vo.id}')" title="删除"> <span
                                                    class="  btn-fab btn-fab-sm shadow btn-Danger"><i
                                                    class="icon icon-close"></i>      </span> </a>
                                        </td>

                                        <td>
                                            <a onclick="omoney('','{$vo.id}')" title="扣款"> <span
                                                    class="  btn-fab btn-fab-sm shadow btn-Secondary "><i
                                                    class="icon icon-shopping-cart"></i>      </span> </a>
                                        </td>
                                        <?php  } ?>

                                    </tr>
                                    {/volist}


                                    </tbody>
                                </table>

                            </div>
                        </div>
                        {$list->render()}

                    </div>


                </div>


            </div>
        </div>
    </div>


    <script>


        function omoney(status, id) {
            if (status == '1') {
                var str = 'all';
            } else {
                if (id == '') {
                    var str = "";
                    $("input:checkbox[name='checkname']:checked").each(function () {
                        str += $(this).val() + ",";
                    });

                    if (str == '') {
                        return false
                    }
                } else {
                    var str = id
                }
            }


            layer.prompt({title: '请输入扣款金额', formType: 3}, function (pass, index) {
                if (!isNaN(pass)) {
                    $.ajax({
                        'type': 'post',
                        'url': '{:url("user/omoney")}',
                        'data': {
                            'id': str,
                            'status': status,
                            'money': pass,
                            'type': 1
                        },
                        'dataType': 'json',
                        'success': function (msg) {
                            if (msg.code == '1') {

                                window.location.reload();
                            } else {
                                layer.closeAll();
                                $('#del').php('<div class="col-md-6" id="alert">' +
                                    '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                    ' <button type="button" class="close" data-dismiss="alert">' +
                                    '<span aria-hidden="true">×</span>' +
                                    '<span class="sr-only">Close</span>' +
                                    '</button>' +
                                    '<strong> 糟糕 !</strong> ' + msg.msg +
                                    '' +
                                    '</div>' +
                                    '</div>');
                                setTimeout("yalert()", 2000)
                            }

                            layer.closeAll();
                            setTimeout("$('#alert').fadeOut(1000)", 2000)
                        },
                        'error': function (err) {
                            layer.closeAll();
                            $('#del').php('<div class="col-md-6" id="alert">' +
                                '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                ' <button type="button" class="close" data-dismiss="alert">' +
                                '<span aria-hidden="true">×</span>' +
                                '<span class="sr-only">Close</span>' +
                                '</button>' +
                                '<strong> 糟糕 !</strong> 服务器错误' +
                                '.请刷新后重试' +
                                '</div>' +
                                '</div>');
                            setTimeout("yalert()", 2000)
                        }
                    })
                    layer.close(index);
                } else {
                    $('.layui-layer-content').append('<br><span style="color: red">请填入纯数字</span>')
                    return false;
                }


            })


        }

    </script>


    <script>
        $("input[name='checkall']").click(function () {
//判断当前点击的复选框处于什么状态$(this).is(":checked") 返回的是布尔类型
            if ($(this).is(":checked")) {
                $("input[name='checkname']").prop("checked", true);
            } else {
                $("input[name='checkname']").prop("checked", false);
            }
        });
    </script>
    {$code==1?'
    <div class="col-md-6" id="alert" style="position:fixed;right:0px;bottom:0px;  width: 350px">
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">
                <span aria-hidden="true">×</span>
                <span class="sr-only">Close</span>
            </button>

            <strong>恭喜 !</strong> 添加成功.
        </div>
    </div>

    ':''}


    {$code==2?'
    <div class="col-md-6" id="alert" style="position:fixed;right:0px;bottom:0px;  width: 350px">
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">
                <span aria-hidden="true">×</span>
                <span class="sr-only">Close</span>
            </button>

            <strong>恭喜 !</strong> 修改成功.
        </div>
    </div>

    ':''}
    {$code==3?'
    <div class="col-md-6" id="alert" style="position:fixed;right:0px;bottom:0px;  width: 350px">
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">
                <span aria-hidden="true">×</span>
                <span class="sr-only">Close</span>
            </button>

            <strong>恭喜 !</strong> 删除成功.
        </div>
    </div>

    ':''}
    <?php if(session('power')=='0'){?>
    <script>
        function del(id) {
            if (id == '') {
                var str = "";
                $("input:checkbox[name='checkname']:checked").each(function () {
                    str += $(this).val() + ",";
                });

                if (str == '') {
                    return false
                }
            } else {
                var str = id
            }
            layer.confirm('您是否删除该数据', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    'type': 'post',
                    'url': '{:url("user/delete")}',
                    'data': {
                        'id': str
                    },
                    'dataType': 'json',
                    'success': function (msg) {
                        if (msg.code == '1') {
                            window.location.reload();
                        } else {
                            layer.closeAll();
                            $('#del').php('<div class="col-md-6" id="alert">' +
                                '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                ' <button type="button" class="close" data-dismiss="alert">' +
                                '<span aria-hidden="true">×</span>' +
                                '<span class="sr-only">Close</span>' +
                                '</button>' +
                                '<strong> 糟糕 !</strong> 删除失败' +
                                '.请刷新后重试' +
                                '</div>' +
                                '</div>');
                        }


                        layer.closeAll();
                        setTimeout("$('#alert').fadeOut(1000)", 2000)
                    },
                    'error': function (err) {
                        layer.closeAll();
                        $('#del').php('<div class="col-md-6" id="alert">' +
                            '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                            ' <button type="button" class="close" data-dismiss="alert">' +
                            '<span aria-hidden="true">×</span>' +
                            '<span class="sr-only">Close</span>' +
                            '</button>' +
                            '<strong> 糟糕 !</strong> 服务器错误' +
                            '.请刷新后重试' +
                            '</div>' +
                            '</div>');
                        setTimeout("yalert()", 2000)
                    }
                })
            })

        }

        function yalert() {

            $('#alert').fadeOut(1000);
            $('#alert').remove()
        }

    </script>


    <script>


        //批量解封 封号
        function status(status, id) {

            if (id == '') {
                var str = "";
                $("input:checkbox[name='checkname']:checked").each(function () {
                    str += $(this).val() + ",";
                });

                if (str == '') {
                    return false
                }
            } else {
                var str = id
            }


            layer.confirm('您是否确定解封、封禁', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    'type': 'post',
                    'url': '{:url("user/status")}',
                    'data': {
                        'id': str,
                        'status': status
                    },
                    'dataType': 'json',
                    'success': function (msg) {

                        window.location.reload();


                        layer.closeAll();
                        setTimeout("$('#alert').fadeOut(1000)", 2000)
                    },
                    'error': function (err) {
                        layer.closeAll();
                        $('#del').php('<div class="col-md-6" id="alert">' +
                            '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                            ' <button type="button" class="close" data-dismiss="alert">' +
                            '<span aria-hidden="true">×</span>' +
                            '<span class="sr-only">Close</span>' +
                            '</button>' +
                            '<strong> 糟糕 !</strong> 服务器错误' +
                            '.请刷新后重试' +
                            '</div>' +
                            '</div>');
                        setTimeout("yalert()", 2000)
                    }
                })
            })

        }

        function yalert() {

            $('#alert').fadeOut(1000);
            $('#alert').remove()
        }

    </script>


    <?php }?>
    <?php if(session('power')=='0'){?>
    <script>
        function money(status, id) {
            if (status == '1') {
                var str = 'all';
            } else {
                if (id == '') {
                    var str = "";
                    $("input:checkbox[name='checkname']:checked").each(function () {
                        str += $(this).val() + ",";
                    });

                    if (str == '') {
                        return false
                    }
                } else {
                    var str = id
                }
            }


            layer.prompt({title: '请输入充值点数', formType: 3}, function (pass, index) {
                if (!isNaN(pass)) {
                    $.ajax({
                        'type': 'post',
                        'url': '{:url("user/money")}',
                        'data': {
                            'id': str,
                            'status': status,
                            'money': pass,
                            'type': 2
                        },
                        'dataType': 'json',
                        'success': function (msg) {
                            if (msg.code == '0') {

                                layer.closeAll();
                                $('#del').php('<div class="col-md-6" id="alert">' +
                                    '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                    ' <button type="button" class="close" data-dismiss="alert">' +
                                    '<span aria-hidden="true">×</span>' +
                                    '<span class="sr-only">Close</span>' +
                                    '</button>' +
                                    '<strong> 糟糕 !</strong> ' + msg.msg +
                                    '.请刷新后重试' +
                                    '</div>' +
                                    '</div>');
                                setTimeout("yalert()", 2000)
                            } else {
                                window.location.reload();

                            }
                            layer.closeAll();
                            setTimeout("$('#alert').fadeOut(1000)", 2000)

                        },
                        'error': function (err) {
                            layer.closeAll();
                            $('#del').php('<div class="col-md-6" id="alert">' +
                                '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                ' <button type="button" class="close" data-dismiss="alert">' +
                                '<span aria-hidden="true">×</span>' +
                                '<span class="sr-only">Close</span>' +
                                '</button>' +
                                '<strong> 糟糕 !</strong> 服务器错误' +
                                '.请刷新后重试' +
                                '</div>' +
                                '</div>');
                            setTimeout("yalert()", 2000)
                        }
                    })
                    layer.close(index);
                } else {
                    $('.layui-layer-content').append('<br><span style="color: red">请填入纯数字</span>')
                    return false;
                }


            })


        }

    </script>

    <?php }?>

    <script>


        //时间补偿
        function ctime() {

            layer.prompt({title: '请输入补偿天数', formType: 5}, function (pass, index) {
                if (!isNaN(pass)) {
                    $.ajax({
                        'type': 'post',
                        'url': '{:url("user/ctime")}',
                        'data': {
                            'day': pass,
                            'type': 2
                        },
                        'dataType': 'json',
                        'success': function (msg) {
                            window.location.reload();

                            layer.closeAll();
                            setTimeout("$('#alert').fadeOut(1000)", 2000)
                        },
                        'error': function (err) {
                            layer.closeAll();
                            $('#del').php('<div class="col-md-6" id="alert">' +
                                '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                                ' <button type="button" class="close" data-dismiss="alert">' +
                                '<span aria-hidden="true">×</span>' +
                                '<span class="sr-only">Close</span>' +
                                '</button>' +
                                '<strong> 糟糕 !</strong> 服务器错误' +
                                '.请刷新后重试' +
                                '</div>' +
                                '</div>');
                            setTimeout("yalert()", 2000)
                        }
                    })
                    layer.close(index);
                } else {
                    $('.layui-layer-content').append('<br><span style="color: red">输入有误</span>')
                    return false;
                }


            })


        }

    </script>
    <script>


        //充值时间
        function btime(id) {
            if (id == '') {
                var str = "";
                $("input:checkbox[name='checkname']:checked").each(function () {
                    str += $(this).val() + "-";
                });

                if (str == '') {
                    return false
                }
            } else {
                var str = id
            }
            var windowWidth = $('body').width();
            console.log(windowWidth);
            if (windowWidth > 1136) {
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['500px', '300px'], //宽高
                    content: '<div class="form-group" style="left:0px">' +
                        ' <label class="control-label">&nbsp;&nbsp;&nbsp;套餐</label>' +
                        '<select id="ctime" class="form-control">' +
                        ' <option value="{$option["d_vip1"]}">体验:{$option["d_vip1"]}元</option>' +
                        ' <option value="{$option["d_vip2"]}">一月:{$option["d_vip2"]}元</option>' +
                        ' <option value="{$option["d_vip3"]}"}>三月:{$option["d_vip3"]}元</option>' +
                        ' <option value="{$option["d_vip4"]}"}>半年:{$option["d_vip4"]}元</option>' +
                        ' <option value="{$option["d_vip5"]}"}>一年:{$option["d_vip5"]}元</option>' +
                        ' <option value="{$option["d_vip6"]}"}>永久:{$option["d_vip6"]}元</option>' +
                        ' </select>' +
                        ' </div>' +
                        '<button class="btn btn-default" onclick="pay(\'' + str + '\')" style="float: right;margin-right: 20px;background-color: #68b828"> 充值</button>'
                });
            } else {
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['80%', '300px'], //宽高
                    content: '<div class="form-group" style="left:0px">' +
                        ' <label class="control-label">&nbsp;&nbsp;&nbsp;套餐</label>' +
                        '<select id="ctime" class="form-control">' +
                        ' <option value="{$option["d_vip1"]}">体验:{$option["d_vip1"]}元</option>' +
                        ' <option value="{$option["d_vip2"]}">一月:{$option["d_vip2"]}元</option>' +
                        ' <option value="{$option["d_vip3"]}"}>三月:{$option["d_vip3"]}元</option>' +
                        ' <option value="{$option["d_vip4"]}"}>半年:{$option["d_vip4"]}元</option>' +
                        ' <option value="{$option["d_vip5"]}"}>一年:{$option["d_vip5"]}元</option>' +
                        ' <option value="{$option["d_vip6"]}"}>永久:{$option["d_vip6"]}元</option>' +
                        ' </select>' +
                        ' </div>' +
                        '<button class="btn btn-default" onclick="pay(\'' + str + '\')" style="float: right;margin-right: 20px;background-color: #68b828"> 充值</button>'
                });
            }

        }
    </script>
    <script>

        function pay(id) {
            var ctime = $('#ctime').val();
            $.ajax({
                'type': 'post',
                'url': '{:url("user/chong")}',
                'data': {
                    'ctime': ctime,
                    'id': id
                },
                'dataType': 'json',
                'success': function (msg) {
                    if (msg.code == '0') {
                        layer.closeAll();
                        $('#del').php('<div class="col-md-6" id="alert">' +
                            '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                            ' <button type="button" class="close" data-dismiss="alert">' +
                            '<span aria-hidden="true">×</span>' +
                            '<span class="sr-only">Close</span>' +
                            '</button>' +
                            '<strong> 糟糕 !</strong>' + msg.msg +
                            '</div>' +
                            '</div>');
                        setTimeout("yalert()", 2000)

                    } else if (msg.code == '1') {

                        window.location.reload();
                    }

                    layer.closeAll();
                    setTimeout("$('#alert').fadeOut(1000)", 2000)
                },
                'error': function (err) {
                    layer.closeAll();
                    $('#del').php('<div class="col-md-6" id="alert">' +
                        '<div class="alert alert-danger"  style="position:fixed;right:0px;bottom:0px;  width: 350px">' +
                        ' <button type="button" class="close" data-dismiss="alert">' +
                        '<span aria-hidden="true">×</span>' +
                        '<span class="sr-only">Close</span>' +
                        '</button>' +
                        '<strong> 糟糕 !</strong> 服务器错误' +
                        '.请刷新后重试' +
                        '</div>' +
                        '</div>');
                    setTimeout("yalert()", 2000)
                }
            })


        }


    </script>

    <script>

        function kill() {
            layer.closeAll();
        }

        setTimeout("$('#alert').fadeOut(1000)", 2000)
    </script>
    <div id="del">

    </div>